<?php

use yii\db\Migration;

class m170605_025028_create_tutor extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }

    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%tutor}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'name' => $this->string()->defaultValue(null).' COMMENT \'导师名称\'',
                'picture' => $this->string(200)->defaultValue(null).' COMMENT \'照片\'',
                'appellation' => $this->string(50)->defaultValue(null) .' COMMENT \'称谓\'',
                'description' => $this->text()->defaultValue(null) .' COMMENT \'简介\'',
                'status' => $this->smallInteger(2)->defaultValue(1) .' COMMENT \'状态 0 禁用 1 启用\'',
                'created_at'   => $this->integer()->defaultValue(0).' COMMENT \'创建时间\''
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v){
            $this->db = $v;
            $this->dropTable('{{%tutor}}');
        }
    }
}
